package agent.client.android.agent;

import jade.core.Agent;
import jade.util.Logger;
import agent.client.android.MainActivity;
import agent.client.android.behaviours.RegistrationControlBehaviour;
import agent.client.android.behaviours.RequestAppointmentBehaviour;
import android.content.Context;

public class AndroidAgent extends Agent implements AgentInterface {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Logger logger = Logger.getMyLogger(this.getClass().getName());
	
	private Context context;
	
	@Override
	protected void setup() {
		// TODO Auto-generated method stub
		super.setup();
	
		registerO2AInterface(AgentInterface.class, this);
		
		Object arguments[] = getArguments();
	
		logger.info("AGENT NAME: "+getAID().getLocalName()+" PASSWORD: "+arguments[0]);
		
		context = (Context)arguments[1];
		
		MainActivity activity = (MainActivity)arguments[2];
		
		RegistrationControlBehaviour registrationControlBehaviour = new RegistrationControlBehaviour(activity);
		registrationControlBehaviour.setPassword(arguments[0].toString());
		
		addBehaviour(registrationControlBehaviour);
	}

	@Override
	protected void takeDown() {
		// TODO Auto-generated method stub
		super.takeDown();
	}

	public void requestAppointment(String dataTransferObject) {
		// TODO Auto-generated method stub
		addBehaviour(new RequestAppointmentBehaviour(dataTransferObject));
	}

	public Context getContext() {
		return context;
	}
}
